package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kotlin.ResultKt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    //Request URL: http://localhost:8500/api/search/albumInfo/channel/1
    @GetMapping("/channel/{category1Id}")
    @Operation(summary = "根据一级分类id获取首页展示的数据")
    public Result channel(@PathVariable(value = "category1Id") Long category1Id){
        List<Map<String, Object>> result = searchService.channel(category1Id);
        return Result.ok(result);
    }

    //Request URL: http://localhost:8500/api/search/albumInfo
    @PostMapping
    @Operation(summary = "搜索专辑")
    public Result search(@RequestBody AlbumIndexQuery query){
        AlbumSearchResponseVo response = searchService.search(query);
        return Result.ok(response);
    }

    //Request URL: http://localhost:8500/api/search/albumInfo/completeSuggest/12
    @GetMapping("/completeSuggest/{keyword}")
    @Operation(summary = "搜索框搜索内容展示提示词")
    public Result completeSuggest(@PathVariable String keyword){
        Set<String> result = searchService.completeSuggest(keyword);
        return Result.ok(result);
    }

    //Request URL: http://localhost:8500/api/search/albumInfo/125
    @GetMapping("/{albumId}")
    @Operation(summary = "根据专辑id获取专辑详情信息")
    public Result getAlbumInfoDetail(@PathVariable Long albumId){
        Map<String,Object> map = searchService.getAlbumInfoDetail(albumId);
        return Result.ok(map);
    }


}

